let calc = new Calculator()

function Calculator() {
	this.methods = {
		'+': (a, b) => a + b,
		'-': (a, b) => a - b,
	}

	this.calculate = function (str) {
		let arr = str.split(' ')
		return this.methods[arr[1]](arr[0], arr[2])
	}

	this.addMethod = function (name, func) {
		this.methods[name] = func
	}
}

// let powerCalc = new Calculator; 没有参数时，这种写法也可以实例化对象。
let powerCalc = new Calculator()

powerCalc.addMethod('*', (a, b) => a * b)
powerCalc.addMethod('/', (a, b) => a / b)
powerCalc.addMethod('**', (a, b) => a ** b)

let result = powerCalc.calculate('2 ** 3')
console.log(result) // 8
